package com.action.boot.mongo.mongo_template.service;

import com.action.boot.mongo.mongo_template.dao.JoinDao;
import com.action.boot.mongo.mongo_template.util.Object2DBObject;
import com.mongodb.DBObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Wuxiang on 2017/11/12.
 */
@Service
public class JoinService {
    @Autowired
    JoinDao joinDao;

    public List<DBObject> getLeftJosin() {
        return joinDao.selectAll();
    }

    public void initLeftJoin() {
        List<DBObject> dbObjects1 = new ArrayList<>();
        List<DBObject> dbObjects2 = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        DBObject dbObject;

        map.put("name", "xiaohong");
        map.put("sex", "女");
        map.put("age", "12岁");
        dbObject = Object2DBObject.change(map);
        dbObjects1.add(dbObject);

        map.clear();
        map.put("name", "xiaoming");
        map.put("sex", "男");
        map.put("age", "14岁");
        dbObject = Object2DBObject.change(map);
        dbObjects1.add(dbObject);

        map.clear();
        map.put("add", "111");
        map.put("minus", "222");
        map.put("patientName", "xiaoming");
        dbObject = Object2DBObject.change(map);
        dbObjects2.add(dbObject);

        map.clear();
        map.put("add", "333");
        map.put("minus", "444");
        map.put("patientName", "xiaoming");
        dbObject = Object2DBObject.change(map);
        dbObjects2.add(dbObject);

        map.clear();
        map.put("add", "555");
        map.put("minus", "666");
        map.put("patientName", "xiaohong");
        dbObject = Object2DBObject.change(map);
        dbObjects2.add(dbObject);

        joinDao.initLeftJoin(dbObjects1, dbObjects2);

    }
}
